package foliotracker.tests;

import static org.junit.Assert.assertEquals;

import java.util.Date;


import org.junit.Before;
import org.junit.Test;

import foliotracker.Portfolio;
import foliotracker.PortfolioCollection;

public class PortfolioCollectionTest {

	private PortfolioCollection portfolios;
	
	@Before
	public void setup(){
		portfolios = new PortfolioCollection();
	}
	
	@Test
	public void addPortfolioTest() 
	{
		Portfolio test1 = new Portfolio("Test1");
		portfolios.addPortfolio(test1);
		
		//check that the size of the list of portfolios is correct;
		assertEquals(1, portfolios.getPortfolios().size());
	}
	
	@Test
	public void getTotalValueTest(){
		
		Portfolio test1 = new Portfolio("Test1");
		test1.buyStock("GOOG", "Google Inc", new Date(), 10, 10, 30);
		portfolios.addPortfolio(test1);
		
		Portfolio test2 = new Portfolio("Test2");
		test2.buyStock("MSFT!", "Microsoft", new Date(), 5, 10, 20);
		portfolios.addPortfolio(test2);
		
		//make sure the total value is correct;
		assertEquals(400, portfolios.getTotalValue(), 0.01);	
		
		//sell some of the stock to alter the total value;
		test1.sellStock("GOOG", 9);
		
		//make sure the total value of the collection has updated;
		assertEquals(130, portfolios.getTotalValue(), 0.01);
		
	}
	
	@Test
	public void getTotalInitialCostTest()
	{
		Portfolio test1 = new Portfolio("Test1");
		test1.buyStock("GOOG", "Google Inc", new Date(), 10, 15, 30);
		portfolios.addPortfolio(test1);
		
		Portfolio test2 = new Portfolio("Test2");
		test2.buyStock("MSFT!", "Microsoft", new Date(), 5, 5, 20);
		portfolios.addPortfolio(test2);
		
		//make sure the total initial value is correct;
		assertEquals(175, portfolios.getTotalCost(), 0.01);
		
		//add some mroe stock;
		test2.buyStock("AAPL", "Apple", new Date(), 20, 10, 12);
		
		//make sure the values have updated;
		assertEquals(375, portfolios.getTotalCost(), 0.01);
		
	}

}
